// packageD/directSeeding/components/ResultDialog/ResultDialog.js
const app = getApp();

Component({

  /**
   * 组件的属性列表
   */
  properties: {
    ResShow: {
      type: Boolean
    },
    resType: {
      type: Object
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    count: 5,
    interFun: null,
    imgHost: app.globalData.imgPath + "live-broadcast-question/question.png",
    integral: "积分"
  },
  lifetimes: {
    attached(){
      this.setData({
        integral: wx.getStorageSync('integral')
      })
    },
    detached() {
      this.clearInterval();
      this.init();
    }
  },
  observers: {
    'ResShow': function (val) {
      if (val) {
        this.setData({
          count: 5
        })
        this.data.interFun = setInterval(() => {
          this.setData({
            count: this.data.count - 1
          })
          console.log(this.data.count)
          if (this.data.count <= 0) {
            this.close();
            this.data.interFun && this.clearInterval_fun();
            return;
          }
        }, 1000);
      } else {
        this.setData({
          count: 5
        })
        this.clearInterval_fun();
      }
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    init() {
      this.count = 5;
      this.interFun = null;
      this.setData({
        count: 5,
        interFun: null
      })
    },
    close() {
      this.triggerEvent('updateResClose', false)
    },
    clearInterval_fun() {
      if (this.data.interFun) {
        clearInterval(this.data.interFun);
        this.data.interFun = null;
      }
    }
  }
})